<?php
class i18n {
   
   var $language;
   var $lang_code;
   var $lang_codes;
	 var $object; //pour acceder aux fonctions de ci
	 
   /**
    * 
    * 
    */
    function i18n()
    {
        $this->object =& get_instance(); 
        //gets available languages
        $this->lang_codes=$this->object->config->item('lang_codes');
        //gets language codes and sets default
        $codes=array_values($this->lang_codes);
        if ($this->object->session->userdata('lang_code')==false) 
            $this->object->session->set_userdata('lang_code',$codes[0]);

        //lang code in POST
        if ($this->object->input->post('lang_code')!=false) {
            $requestedLangCode=$this->object->input->post('lang_code');
            if (in_array($requestedLangCode,$codes))
                $this->object->session->set_userdata('lang_code',$requestedLangCode);
        }
        
        //lang code in URI
        if ($this->object->config->item('lang_code')) {
            $this->object->session->set_userdata('lang_code',$this->object->config->item('lang_code'));
        }
        
        $flipCodes=array_flip($this->lang_codes);
        $this->language=$flipCodes[$this->object->session->userdata('lang_code')];
        $this->lang_code=$this->object->session->userdata('lang_code');
    }
    
    function getLang()
    {
        return $this->language;
    }

    function getLangCode()
    {
        return $this->lang_code;
    }

    function getAllLang()
    {
        return $this->lang_codes;
    }
}
?>
